package com.xiyuan.smartutils.template.engine.exception;

import com.xiyuan.smartutils.Validates;

import com.xiyuan.smartutils.template.engine.expression.Expression;

/***
 * 定义表达式解析异常
 * 
 * @author lgz 2020年10月26日 新建与整理
 * 
 */
public class ExpressionException extends RuntimeException
{
    private static final long serialVersionUID = 1L;
    
    private String path;
    private int line;
    private int column;
    
    private String message;
    public ExpressionException(Expression expression, String message)
    {
        this(expression, message, null);
    }
    
    public ExpressionException(Expression expression, Throwable cause)
    {
        this(expression, cause != null ? cause.getMessage() : null, cause);
    }
    
    public ExpressionException(Expression expression, String message, Throwable cause)
    {
        this(expression.getPath(), expression.getLine(), expression.getColumn(), message, cause);
    }
    
    public ExpressionException(String path, int line, int column, String message, Throwable cause)
    {
        super(new StringBuilder("[").append(Validates.isBlank(path) ? "自定义表达式" : path).append("]").append("[第").append(line).append("行][第").append(column).append("列]")
            .append(message == null ? "" : message).toString(), cause);
        
        this.path = path;
        this.line = line;
        this.column = column;
        this.message = message;
    }
    
    public String getPath()
    {
        return path;
    }
    
    public int getLine()
    {
        return line;
    }
    
    public int getColumn()
    {
        return column;
    }
    
    public String getCusomMessage(){
        return message;
    }
}
